package monitor

import (
	"gitee.com/alex_li/gpio/internal/etc"
	"gitee.com/alex_li/gpio/internal/pin"
	"github.com/lishimeng/go-log"
	"github.com/lishimeng/x/container"
)

func initPin() (err error) {
	var gpioManager pin.GPIOManager
	err = container.Get(&gpioManager)
	if err != nil {
		return
	}

	var pinList = etc.Config.Pins.Pin
	for _, pinNumber := range pinList {
		if etc.Config.Pins.Dev == 1 {
			log.Info("dev open pin: %d[direct:out]", pinNumber)
		} else {
			_, err = gpioManager.OpenPin(pinNumber, pin.OUT)
		}

		if err != nil {
			return
		}
	}
	return
}
